package leetCode;

public class StoneGameII {
    public int stoneGameII(int[] piles) {
        return helper(0, 1, new int[]{0, 0}, piles, 0);
    }

    private int helper(int i, int M, int[] sums, int[] piles, int person) {
        if (i == piles.length) {
            return 0;
        }
        int maxSum = 0;
        int tmp = 0;
        int maxX=0;
        for (int x = 0; x < 2 * M; i++) {
            if (i + x == piles.length) {
                break;
            }
            tmp += piles[i + x];
            int[] tmpSum = new int[]{sums[0], sums[1]};
            tmpSum[person] += tmp;
            helper(i + 1 + x, Math.max(M, x + 1), tmpSum, piles, person == 0 ? 1 : 0);
            if(tmpSum[person]>maxSum){
                maxSum=tmpSum[person];
                maxX=x;
            }
        }
        System.out.println("i:" + i + "person:" + person + "maxSum:" + maxSum);
        return maxSum;
    }

    public static void main(String[] args) {
        int[] piles = {2, 7, 9, 4, 4};
        int x = new StoneGameII().stoneGameII(piles);
        System.out.print(x);
    }
}
